package holiday_demo.classAndInterface.demo10;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Return_interface {
    public static void main(String[] args) {
        /*左边是接口，右边是实现类
        向下转型
        public class ArrayList<E> extends AbstractList<E>
        implements List<E>, RandomAccess, Cloneable, java.io.Serializable
{
         */
        List<String> list=new ArrayList<>();

        List<String> result=addName(list);
        //遍历列表
        System.out.println("列表内元素有：");
        for (int i = 0; i < result.size(); i++) {
            System.out.println(result.get(i));
        }
    }
    public static List<String> addName(List<String> list){
        Scanner read=new Scanner(System.in);
        for (int i = 0; i < 4; i++) {
            System.out.print("输入列表元素：");
            list.add(read.next());
        }
        return list;
    }
}
